<template>
	<view class="template">
		<!-- 视频 -->
		<view class="">
			<video :src="videoUrl" style="width:100%;height:100vh" :autoplay="true" :custom-cache="false"></video>
		</view>
		<!-- 返回首页 -->
		<view class="action_home" :style="[{height:CustomBar + 'px',paddingTop:StatusBar + 'px'}]"
			v-if="userInfo && userInfo.phone && userInfo.userLevelId == 2 && userInfo.enable == '1'">
			<image src="https://fs-mix.oss-cn-beijing.aliyuncs.com/1/material/e8b79ac2-2590-46df-aa6d-306dc26814e9.png"
				mode="" style="width:40rpx;height:40rpx" @click="GoHome"></image>
		</view>
		<view class="" style="position: fixed;bottom: 120rpx;color: #fff;width: 100%;padding: 0 30rpx"
			v-if="!showphonePop">
			<view class="" style="margin-bottom: 20rpx;font-size: 30rpx;" v-if="info">
				{{info}}
			</view>
			<view class="flex-row-between" style="width: 100%;align-items: stretch;">
				<view class="" style="width: 58%;" @click="jumpUrl">
					<button style="background-color: #EB2A4A;color: #fff;font-size: 36rpx;">立即购买</button>
				</view>
				<view class="" style="width: 38%;" @click="showphonePop=true">
					<button
						style="background-color: #4F91F5;color: #fff;font-size: 28rpx;height: 100%;display: flex;justify-content: center;align-items: center;">电话咨询</button>
				</view>
			</view>
		</view>
		<view class="" style="position: fixed;bottom: 120rpx;color: #fff;width: 100%;padding: 0 30rpx;"
			v-if="showphonePop">
			<button style="margin-bottom: 20rpx;color: #5494F5;font-size: 36rpx;" @click="phoneClick('13287958570')">
				<text class="cuIcon-dianhua"></text>
				<text style="margin-left: 20rpx;">呼叫13287958570</text>
			</button>
			<button @click="showphonePop=false" style="color: #5494F5;font-size: 36rpx;">取消</button>
		</view>
	</view>
</template>

<script>
	import api from 'utils/api'

	export default {
		name: 'goods-video',
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				goodsSpu: {},
				userId: null,
				showphonePop: false,
				videoUrl: '',
				info: '',
				userInfo: uni.getStorageSync('user_info'),
				spuId: ''
			}
		},
		onLoad(options) {
			if (options.spuId) {
				this.spuId = options.spuId
				this.goodsGet(options.spuId)
				this.userId = options.userId
			}
		},
		onShow() {
			// wx.hideShareMenu()
			wx.showShareMenu({
				menus: ['shareAppMessage', 'shareTimeline']
			})
		},		
		onShareAppMessage() {
			return {
				title: this.info,
				imageUrl: this.goodsSpu.spuShare&&this.goodsSpu.spuShare.imgUrl ? this.goodsSpu.spuShare.imgUrl : this.goodsSpu.picUrls && this.goodsSpu.picUrls.length ? this.goodsSpu.picUrls[0] : null,
				path: '/pages/goods/goods-video/index?spuId=' + this.spuId + '&userId=' + this.userId
			}
		},
		onShareTimeline() {
			return {
				title: this.info,
				imageUrl: this.goodsSpu.spuShare&&this.goodsSpu.spuShare.imgUrl ? this.goodsSpu.spuShare.imgUrl : this.goodsSpu.picUrls && this.goodsSpu.picUrls.length ? this.goodsSpu.picUrls[0] : null,
				path: '/pages/goods/goods-video/index?spuId=' + this.spuId + '&userId=' + this.userId
			}
		},
		methods: {
			GoHome() {
				uni.redirectTo({
					url: '/pages/goods/goods-detail/index?id=' + this.spuId
				});
			},
			goodsGet(goodsId) {
				api.goodsGet1(goodsId).then(res => {
					this.goodsSpu = res.data || {}
					this.videoUrl = this.goodsSpu.spuShare && this.goodsSpu.spuShare.videoUrl ? this.goodsSpu
						.spuShare.videoUrl : ''
					this.info = this.goodsSpu.spuShare && this.goodsSpu.spuShare.info ? this.goodsSpu.spuShare
						.info : this.goodsSpu.name
				});
			},
			jumpUrl() {
				if (this.goodsSpu.shelf == '0') {
					uni.showModal({
						title: '提示',
						content: '抱歉，该商品已下架',
						confirmText: '返回',
						showCancel: false,
						success(res) {}
					})
					return
				}

				if (!this.goodsSpu.skus || !this.goodsSpu.skus.length) {
					uni.showModal({
						title: '提示',
						content: '抱歉，该商品已关闭',
						confirmText: '返回',
						showCancel: false,
						success(res) {}
					})
					return
				}

				api.shareInfo({
					skuId: this.goodsSpu.skus[0].id,
					userId: this.userId
				}).then(res => {
					let shareId = res.data.id
					wx.navigateToMiniProgram({
						appId: 'wxa0e70c974a1c9bc7', //appid
						path: '/pages_subject/hwOrder/hw_order?scene=' + shareId, //path
						envVersion: 'release',
						success(res) {
							console.log('成功')
						},
						fail(err) {
							console.log(err);
						}
					})
				})
			},
			phoneClick(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				});
			}
		}
	}
</script>

<style scoped>
	.action_home {
		position: fixed;
		top: 0;
		color: #fff;
		width: 100%;
		padding-left: 30rpx;
		display: flex;
		align-items: center;
	}

	.l_icon {
		background-color: #fff;
		border-radius: 50%;
		width: 90rpx;
		height: 90rpx;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.l_icon .icon {
		color: #38AAE3;
		font-size: 50rpx;

	}

	.l_text {
		color: #fff;
		margin-top: 10rpx;
		margin-bottom: 30rpx;
	}
</style>